package
{
	import flash.display.Sprite;
	import flash.events.NetStatusEvent;
	import flash.events.SyncEvent;
	import flash.net.NetConnection;
	import flash.net.SharedObject;

	//import flash.net.ObjectEncoding;
	public class TestBasicSO extends Sprite
	{
		private var test_so:SharedObject;

		private var nc:NetConnection;

		private var monthDay:Date;

		private var good:Boolean;

		public function TestBasicSO()
		{
			//NetConnection.defaultObjectEncoding=flash.net.ObjectEncoding.AMF0;
			//Connect
			var rtmpNow:String = "rtmp://192.168.1.209/livepkgrTest";
			nc = new NetConnection;
			nc.connect(rtmpNow);
			nc.addEventListener(NetStatusEvent.NET_STATUS, doSO);
		}

		private function doSO(e:NetStatusEvent):void
		{
			good = e.info.code == "NetConnection.Connect.Success";
			if (good)
			{
				//Set up shared object
				test_so = SharedObject.getRemote("test", nc.uri, false);
				monthDay = new Date;
				test_so.connect(nc);
				test_so.addEventListener(SyncEvent.SYNC, seeSO);
			}
		}

		private function seeSO(se:SyncEvent):void
		{
			trace(se.changeList[0].code);
			switch (se.changeList[0].code)
			{
				case "clear":
					showSO();
					break;
				case "success":
					showSO();
					break;
				case "change":
					showSO();
					break;
			}
		}

		private function showSO():void
		{
			trace(test_so.data.city);
			trace(test_so.data.dayOfMonth);
			trace(test_so.data.verity);
			trace(test_so.data.bunch);
			
			trace(JSON.stringify(test_so.data));
		}
	}
}
